<template>
  <div
    id="ultrame-canvas-container"
    class="center"
    droppable="true"
    :style="{
      marginLeft: dragController.centerHorizontalMargin / 2 + 'px',
      marginRight: dragController.centerHorizontalMargin / 2 + 'px',
    }"
    @dragstart="handleDragstart($event)"
    @dragenter="handleDragenter($event)"
    @dragover="handleDragover($event)"
    @drop="handleDrop($event)"
    @dragend="handleDragend($event)"
  >
    <div
      v-show="dragController.selectedWidgets.widgets.length"
      class="formHandleBtnContainer"
    >
      <el-button type="warning" plain size="small" @click="previewForm"
        >预览表单</el-button
      >
      <el-button type="success" plain size="small" @click="saveForm"
        >保存</el-button
      >
    </div>
    <div id="ultrame-canvas"></div>
    <Preview :previewVisible.sync="previewVisible" />
  </div>
</template>

<script>
import Preview from "./Preview.vue";

export default {
  name: "Center",
  components: { Preview },
  props: {
    dragController: {
      type: Object,
      require: true,
    },
  },
  data() {
    return {
      previewVisible: false,
    };
  },
  created() {},
  methods: {
    previewForm() {
      this.previewVisible = true;
    },
    saveForm() {
      console.log("saveForm");
      // TODO 保存form配置到数据库
      this.$router.replace("/formList")
    },
    handleDragstart(ev) {
      this.dragController._handleDragstart.call(this.dragController, ev);
    },
    handleDragenter(ev) {
      this.dragController._handleDragenter.call(this.dragController, ev);
    },
    handleDragover(ev) {
      this.dragController._handleDragover.call(this.dragController, ev);
    },
    handleDrop(ev) {
      this.dragController._handleDrop.call(this.dragController, ev);
    },
    handleDragend(ev) {
      this.dragController._handleDragend.call(this.dragController, ev);
    },
  },
};
</script>

<style lang="scss" scoped>
.center {
  flex: 1;
  box-shadow: 0 0 12px 1px #f1f1f1;
  padding: 60px 15px 15px;
  box-sizing: border-box;
  position: relative;
  .formHandleBtnContainer {
    position: absolute;
    top: 20px;
    right: 20px;
  }
}
</style>